$(function () {
    $(".target.free2").on("tap", function (e) {
        var free2 = $(this);
        joinWifiFree2(free2);//call from lib.js
        e.preventDefault();
    });
});

function joinWifiFree2(free2) {
    var custom_landing_page = free2.data('landing_page');
    var url = custom_landing_page == undefined ? landing_page : custom_landing_page;
    //console.log(url);
    Toast.showWait();
    $.ajax({
        type: "GET",
        url: baseurl + "campaign-free",
        timeout: 5000,
        data: {
            mac: mac,
            nasid: nasid,
            name_device: name_device,
            id_campaign: id_campaign,
            landing_page: url,
            id_place: id_place,
            type_time_session: type_time_session
        },
        success: function (data) {
            if (data == '200') {
                Toast.showMessage({typeMessage: 'success'});
                setTimeout(function () {
                    Toast.close();
                    Toast.showWait({text: "Truy cập internet...", width: "150px"});
                    location.href = authentication_link;
                }, 1000);
            } else {
                setTimeout(function () {
                    Toast.close();
                    Toast.show({text: "Có lỗi hệ thống."});
                }, 300);
            }
        },
        error: function () {
            Toast.close();
            Toast.show({text: "Xảy ra lỗi, vui lòng thử lại."});
        }
    });
}